<template lang="html">
  <div class="container" v-loading="loading">
      <div class="search">
          <div class="maintain_total">维修次数合计：<span>{{totalPage}}</span></div>
          <el-form :inline="true" class="demo-form-inline">
              <el-form-item>
                <el-input class="form_input" v-model="searchText" placeholder=""></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" :disabled="loading" size="small" @click="onSubmit">搜索</el-button>
              </el-form-item>
              <el-form-item>
                <datePicker startEndTime @onFilter="onFilter" />
              </el-form-item>
              <el-form-item>
                <span>统计时间：{{statisTime}}</span>
              </el-form-item>
          </el-form>



          <!-- <div class="export_excl">
            <el-button size="small" :disabled="isShutdownAudit" @click="exportExcl" type="primary">导出<i class="el-icon-upload el-icon--right"></i></el-button>
          </div> -->
      </div>

      <div class="tables">
          <el-table :data="tableData" @selection-change="handleSelectionChange" :row-class-name="rowStyle" border :header-cell-style="{background:'#f5f5f5',color:'#666'}" style="width: 100%">
            <el-table-column type="selection" width="40"></el-table-column>
            <el-table-column prop="mId" label="ID" align="center"></el-table-column>
            <el-table-column prop="userName" label="姓名" align="center"></el-table-column>
            <el-table-column prop="phone" label="手机号" align="center"></el-table-column>
            <el-table-column prop="branchStoreName" label="所属店铺" align="center"></el-table-column>
            <el-table-column prop="shopCount" label="购买件数" align="center"></el-table-column>
            <el-table-column prop="afterSalaCount" label="维修次数" align="center"></el-table-column>
            <el-table-column prop="repairRatio" label="返修率" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.repairRatio + '%'}}</span>
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center">
              <template slot-scope="scope">
                <el-button size="mini" type="danger" @click="handleDetail(scope.row)">详情</el-button>
              </template>
            </el-table-column>
          </el-table>
          <pagination @handleSizeChange="handleSizeChange" @handleCurrentChange="handleCurrentChange" :currentPage="currentPage" :totalPage="totalPage" />
      </div>


    </div>
</template>

<script>
export default {
  data(){
    return {
      loading: false,
      searchText: '',
      statisTime: '',
      date: [],
      year: '',
      month: '',
      day: '',
      tableData: [],
      currentData: [],
      currentPage: 1,
      totalPage: 0,
      pageSize: 10,
      id: null,
    }
  },
  computed:{
    isShutdownAudit:function(){
        return this.currentData.length == 0?true:false;
    }
  },

  created(){
    this.id = window.sessionStorage.getItem("maintain_designer");;
    this.getServeData();
  },

  methods: {
    getServeData(){
      this.loading = true;
      this.$http.selectDataStatsDesignerDetailPage({
        id: this.id,
        query: this.searchText,
        startTime: (this.date&&this.date[0]) || '',
        endTime: (this.date&&this.date[1]) || '',
        dayTime: this.day,
        monthTime: this.month,
        yearTime: this.year,
        pageNumber: this.currentPage,
        pageSize: this.pageSize
      }).then(res=>{
        this.loading = false;
        this.tableData = res.data.rows;
        this.totalPage = res.data.total;
        this.pageSize = res.data.pageSize;
      })
    },
    onFilter(e){
      this.statisTime = e.val;
      this.date = [];
      this.year = '';
      this.month = '';
      this.day = '';
      switch (e.key) {
        case 1: this.day = e.val; break;
        case 2: this.month = e.val; break;
        case 3: this.year = e.val; break;
        case 4:
            this.date = [...e.val];
            if(e.val[0]) this.statisTime = `${e.val[0]} - ${e.val[1]}`;
            else this.statisTime = '';
         break;
      }
      this.onSubmit()
    },
    rowStyle({row,rowIndex}) {
      for(let i=0;i<this.currentData.length;i++){
        if(JSON.stringify(row) == JSON.stringify(this.currentData[i])){
          return 'row_style';
        }
      }
    },
    handleSelectionChange(e){
      this.currentData = [];
      this.currentData = this.currentData.concat(e);
    },

    handleDetail(e){
      window.sessionStorage.setItem("designer_order_list", e.mId);
      this.$router.push({path: '/statistics/maintain_statistics/designer_order_list'});
    },
    onSubmit(){
      this.handleCurrentChange(1);
    },
    handleSizeChange(e){
      this.pageSize = e;
      this.handleCurrentChange(1);
    },
    handleCurrentChange(e){
      this.currentPage = e;
      this.getServeData();
    },

    // exportExcl(){
    //   let aId = [];
    //   this.currentData.forEach(item=>{aId.push(item.commodityDetailId)});
    //   this.$confirm('确定要导出吗？').then(()=>{
    //     this.exportsAPI(aId.join(','));
    //   }).catch(e=>0);
    // }
  }
}
</script>

<style lang="css" scoped>
/deep/.el-table .row_style{
  background-color: #f8f8f8 !important;
}
.maintain_total{
  font-size: 14px;
  color: #333;
  margin-right: 20px;
}
.maintain_total span{
  font-size: 24px;
  color: #FF4141;
}
.search {
  flex-wrap: wrap;
}
.search .demo-form-inline{
  min-width: 1200px;
}
.active{
  color: #FFF;
  background-color: #409EFF;
  border-color: #409EFF;
}
.search{
  display: flex;
  position: relative;
}
.export_excl{
  position: absolute;
  right: 0
}
</style>
